// license-header java merge-point
/**
 * This is only generated once! It will never be overwritten.
 * You can (and have to!) safely modify it by hand.
 * TEMPLATE:    SpringServiceImpl.vsl in andromda-spring cartridge
 * MODEL CLASS: carmanagement::com.volkwagen.management::service::UserManagementService
 * STEREOTYPE:  Service
 */
package com.volkwagen.management.service;

import com.volkwagen.management.domain.Status;
import com.volkwagen.management.domain.User;
import com.volkwagen.management.domain.UserDao;
import com.volkwagen.management.vo.UserSearchCriteriaVO;
import com.volkwagen.management.vo.UserUpdateVO;
import com.volkwagen.management.vo.UserVO;
import java.util.ArrayList;
import java.util.List;

/**
 * @see com.volkwagen.management.service.UserManagementService
 */
public class UserManagementServiceImpl
        extends UserManagementServiceBase {

    /**
     * @see com.volkwagen.management.service.UserManagementService#getAllUsers()
     */
    protected List handleGetAllUsers()
            throws Exception {
        return new ArrayList(getUserDao().loadAll(UserDao.TRANSFORM_USERVO));
    }

    @Override
    protected UserVO handleCreateUser(String username, String firstName, String lastName, String password) throws
            Exception {
        UserVO userVO = (UserVO) getUserDao().create(UserDao.TRANSFORM_USERVO, username, firstName, lastName, password,
                Status.ACTIVE);
        return userVO;

    }

    @Override
    protected List handleFindUsers(UserSearchCriteriaVO criteria) throws Exception {
        List users = this.getUserDao().findByCriteria(criteria);
        this.getUserDao().toUserSumaryVOCollection(users);
        return users;
    }

    @Override
    protected UserUpdateVO handleFindUser(Long id) throws Exception {
        return (UserUpdateVO) this.getUserDao().get(UserDao.TRANSFORM_USERUPDATEVO, id);
    }

    @Override
    protected void handleUpdateUser(UserUpdateVO updatingUserVo) throws Exception {
        User user = this.getUserDao().load(updatingUserVo.getId());
        user.setFirstName(updatingUserVo.getFirstName());
        user.setLastName(updatingUserVo.getLastName());
        user.setPastword(updatingUserVo.getPastword());
        user.setStatus(updatingUserVo.getStatus());
        this.getUserDao().update(user);
    }

    @Override
    protected List handleGetAllShortInfoUsers() throws Exception {
        return new ArrayList(this.getUserDao().loadAll(UserDao.TRANSFORM_SHORTUSERVO));
    }
}
